package com.ewzj.bigdata.mvp.ui.activity

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle

import com.ewzj.bigdata.R
import com.ewzj.bigdata.di.component.DaggerPhoneBindingActivityComponent
import com.ewzj.bigdata.di.module.PhoneBindingActivityModule
import com.ewzj.bigdata.mvp.contract.PhoneBindingActivityContract
import com.ewzj.bigdata.mvp.presenter.PhoneBindingActivityPresenter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import com.jess.arms.utils.DeviceUtils
import kotlinx.android.synthetic.main.activity_phone_binding.*
import kotlinx.android.synthetic.main.titile_red.*

class PhoneBindingActivity : BaseActivity<PhoneBindingActivityPresenter>(),PhoneBindingActivityContract.View {
    override fun showEnableCode(along: Long) {
        tv_code.setEnabled(false)
        tv_code.setTextColor(resources.getColor(R.color.color_text_gray))
        tv_code.setBackgroundResource(R.drawable.tag_drawable)
        tv_code.setText((60 - along).toString().plus( "秒"))
    }

    override fun showAbleCode() {
        tv_code.setEnabled(true)
        tv_code.setTextColor(resources.getColor(R.color.maingreen))
        tv_code.setBackgroundResource(R.drawable.green_white_5)
        tv_code.setText("验证")
    }
    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerPhoneBindingActivityComponent.builder().appComponent(appComponent)
                .phoneBindingActivityModule(PhoneBindingActivityModule(this))
                .build().inject(this)
    }

    override fun initView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_phone_binding
    }

    override fun initData(savedInstanceState: Bundle?) {
        initClick()
    }

    private fun initClick() {
        tv_title.text="手机绑定"
        RxView.clicks(iv_back).subscribe({finish()})
        RxView.clicks(tv_code).subscribe({mPresenter.sendSms(et_phone.text.toString())})
        RxView.clicks(tv_send).subscribe({
            DeviceUtils.hideSoftKeyboard(this,et_phone)
            mPresenter.bindPhone(et_phone.text.toString(),et_code.text.toString())})
    }

    override fun showLoading() {

    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {

    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }


}
